﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ITAP.ShprossesBuilder.Editor
{
    public partial class PreferencesForm : Form
    {
        private Preferences preferences;

        public Preferences Preferences
        {
            get { return preferences; }
        }

        public PreferencesForm()
        {
            this.preferences = (Preferences)GlobalPreferences.Preferences.Clone();

            InitializeComponent();
            this.dimensionsOptionsDraft.ShowOptions(this.preferences.DraftDimensions);
            this.dimensionsOptionsEditor.ShowOptions(this.preferences.EditorDimensions);

            if (GlobalPreferences.Preferences.MaterialsTabOrientation == Orientation.Horizontal)
                this.comboBoxMaterialsTabPosition.SelectedIndex = 0;
            else
                this.comboBoxMaterialsTabPosition.SelectedIndex = 1;
            
            if (GlobalPreferences.Preferences.HistoryDepth < this.numericUpDownHistoryDepth.Minimum ||
               GlobalPreferences.Preferences.HistoryDepth > this.numericUpDownHistoryDepth.Maximum)
                this.numericUpDownHistoryDepth.Value = this.numericUpDownHistoryDepth.Minimum;
            else
                this.numericUpDownHistoryDepth.Value = GlobalPreferences.Preferences.HistoryDepth;

            if (GlobalPreferences.Preferences.ThumbnailSize < this.numericUpDownThumbnailSize.Minimum ||
               GlobalPreferences.Preferences.ThumbnailSize > this.numericUpDownThumbnailSize.Maximum)
                this.numericUpDownThumbnailSize.Value = this.numericUpDownThumbnailSize.Minimum;
            else
                this.numericUpDownThumbnailSize.Value = GlobalPreferences.Preferences.ThumbnailSize;
        }

        private void comboBoxDimensionType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //ComboBox comboBox = sender as ComboBox;
            //this.dimensionsOptions.Show(comboBox.SelectedItem as DimensionsPreferences);
        }

        private void comboBoxDimensionType_SelectedValueChanged(object sender, EventArgs e)
        {

        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            GlobalPreferences.Preferences = this.preferences; 
        }

        private void numericUpDownHistoryDepth_ValueChanged(object sender, EventArgs e)
        {
            this.preferences.HistoryDepth = (int)numericUpDownHistoryDepth.Value;
        }

        private void numericUpDownThumbnailSize_ValueChanged(object sender, EventArgs e)
        {
            this.preferences.ThumbnailSize = (int)numericUpDownThumbnailSize.Value;
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {

        }

        private void comboBoxMaterialsTabPosition_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.comboBoxMaterialsTabPosition.SelectedIndex == 0)
                this.preferences.MaterialsTabOrientation = Orientation.Horizontal;
            else if (this.comboBoxMaterialsTabPosition.SelectedIndex == 1)
                this.preferences.MaterialsTabOrientation = Orientation.Vertical;
        }
    }
}
